﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.IO;

namespace LikeTryHacker
{
    public class SmtpHelper
    {
        private static SmtpClient client = new SmtpClient("HSHAXPLTR8W7T4G", 25);

        static SmtpHelper()
        {
            client.UseDefaultCredentials = true;
        }

        public static bool Send(string body, string userName)
        {
            var result = false;
            try
            {
                MailMessage message = new MailMessage();
                message.To.Add("zggyh2006@yahoo.com.cn");
                message.From = new MailAddress("robot@liketry.com","喜试机器人");
                message.Subject = string.Format("{0} -- [{1}] Status Report ",DateTime.Now.ToString("yyyy-MM-dd"),userName);
                message.Body = body;
                client.Send(message);
                result = true;
            }
            catch(Exception exp)
            {
                var fileName = DateTime.Now.ToString("yyyy/MM/dd HH:mm:sssss");
                using (var fs = File.Create(fileName))
                {
                    var bytes = Encoding.Default.GetBytes(body);
                    fs.Write(bytes, 0, bytes.Length);
                }
            }
            
            return result;
            
        }
    }
}
